using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class KnifeAttack : MonoBehaviour
{
    public MyKnife knife;
    public Player player;
    public float hitValueFactor;
    public string Name;
    void OnTriggerEnter2D(Collider2D collision)
    {
        
        if (collision.gameObject.tag == "Enemy" && !knife.checkHitEnemy(collision.gameObject))
        {
            
            Enemy The_enemy = collision.gameObject.GetComponent<Enemy>();
            Debug.Log("hit");
            The_enemy.Hurt(knife.damageValue);

            Vector2 dir = collision.transform.position - transform.position;
            The_enemy.BackOff(knife.hitValue * hitValueFactor, dir.normalized);

            knife.addHitEnemy(collision.gameObject);

            if (Name == "down")
            {
                player.BackOff(knife.hitValue * hitValueFactor, Vector2.up);
            }
        }
    }
}
